package com.qf.controller;


import com.qf.service.DtsAdminStatService;
import com.qf.util.ResponseUtil;
import com.qf.vo.DayStatis;
import com.qf.vo.StatVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collector;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/admin/stat")
public class DtsAdminStatController {
@Autowired
DtsAdminStatService statService;

@RequestMapping("/user")
    public Object statUser(){

    StatVo statVo=new StatVo();
    String[] columns =new String[2];
    columns[0]="day";columns[1]="users";
    statVo.setColumns(columns);
    List<DayStatis> userlist=statService.select();
    List<Map<String,Object>> list=userlist.stream().map(row->{
        Map<String,Object> list1=new HashMap<>();
        list1.put("day",row.getDayStr());
        list1.put("users",row.getCnts());
        return list1;
    }).collect(Collectors.toList());
    statVo.setRows(list);
     Map<String,Object>  data=new HashMap<>();
       data.put("columns",statVo.getColumns());
       data.put("rows",statVo.getRows());
       return ResponseUtil.ok(data);
    }
}
